# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from utils.models import BaseModel
from django.db import models
from manufacturer.models import AuthorityCode


class ResourceManagement(BaseModel):
    """ 资源管理 """
    name = models.CharField(max_length=200, null=True, blank=True, verbose_name=u"资源名称")
    RT0 = "0"
    RT1 = "1"
    RT = (
        (RT0, u"图片"),
        (RT1, u"视频")
    )
    rtype = models.CharField(choices=RT, max_length=1, null=True, blank=True, verbose_name=u"资源类型")
    PM0 = "0"
    PM1 = "1"
    PM2 = "2"
    PM3 = "3"
    PM4 = "4"
    PM5 = "5"
    PM = (
        (PM0, u"纯视频"),
        (PM1, u"1/2视频"),
        (PM2, u"1/3视频"),
        (PM3, u"纯图片"),
        (PM4, u"1/2图片"),
        (PM5, u"1/3图片"),
    )
    play_mode = models.CharField(choices=PM, max_length=1, null=True, blank=True, verbose_name=u"播放模式")
    TT0 = "0"
    TT1 = "1"
    TT = (
        (TT0, u"单屏"),
        (TT1, u"双屏")
    )
    ttype = models.CharField(choices=TT, max_length=1, null=True, blank=True, verbose_name=u"适用终端")
    file = models.CharField(max_length=200, null=True, blank=True, verbose_name=u"文件")
    file_size = models.IntegerField(default=0, verbose_name=u"文件大小")


class PlayingQueue(BaseModel):
    """ 队列 """
    name = models.CharField(max_length=200, null=True, blank=True, verbose_name=u"队列名称", unique=True)
    QT0 = "0"
    QT1 = "1"
    QT2 = "2"
    QT = (
        (QT0, u"传媒"),
        (QT1, u"公告"),
        (QT2, u"滚动"),
    )
    qtype = models.CharField(choices=QT, max_length=1, null=True, blank=True, verbose_name=u"队列类型")
    qdesc = models.CharField(max_length=200, null=True, blank=True, verbose_name=u"队列描述")
    TT0 = "0"
    TT1 = "1"
    TT = (
        (TT0, u"单屏"),
        (TT1, u"双屏")
    )
    ttype = models.CharField(choices=TT, max_length=1, null=True, blank=True, verbose_name=u"适用终端")
    create_user = models.CharField(max_length=20, null=True, blank=True, verbose_name=u"创建人员")
    update_user = models.CharField(max_length=20, null=True, blank=True, verbose_name=u"修改人员")


class PlayingQueueMaterial(BaseModel):
    """ 设定队列"""
    play_queue = models.ForeignKey(PlayingQueue, null=True, blank=True, verbose_name=u"对应的队列")
    PQT0 = "0"
    PQT1 = "1"
    PQT2 = "2"
    PQT = (
        (PQT0, u"传媒"),
        (PQT1, u"公告"),
        (PQT2, u"滚动"),
    )
    pqtype = models.CharField(choices=PQT, max_length=1, null=True, blank=True, verbose_name=u"队列类型")
    PM0 = "0"
    PM1 = "1"
    PM2 = "2"
    PM3 = "3"
    PM4 = "4"
    PM5 = "5"
    PM = (
        (PM0, u"纯视频"),
        (PM1, u"1/2视频"),
        (PM2, u"1/3视频"),
        (PM3, u"纯图片"),
        (PM4, u"1/2图片"),
        (PM5, u"1/3图片"),
    )
    play_mode = models.CharField(choices=PM, max_length=1, null=True, blank=True, verbose_name=u"播放模式")
    NT0 = "0"
    NT1 = "1"
    NT = (
        (NT0, u"常驻公告"),
        (NT1, u"临时公告"),
    )
    ntype = models.CharField(choices=NT, max_length=1, null=True, blank=True, verbose_name=u"公告类型")
    DT0 = "0"
    DT = (
        (DT0, u"文字"),
    )
    dtype = models.CharField(choices=DT, max_length=1, null=True, blank=True, verbose_name=u"数据类型")
    ISD0 = "0"
    ISD1 = "1"
    ISD = (
        (ISD0, u"未停用"),
        (ISD1, u"停用"),
    )
    is_disabled = models.CharField(max_length=1, null=True, blank=True, verbose_name=u"是否停用")
    # name = models.CharField(max_length=200, null=True, blank=True, verbose_name=u"素材名称")
    # files = models.CharField(max_length=200, null=True, blank=True, verbose_name=u"文件")
    play_time = models.IntegerField(null=True, blank=True, default=0, verbose_name=u"播放时间")
    retention_time = models.IntegerField(null=True, blank=True, default=0, verbose_name=u"保留时间")
    content = models.CharField(null=True, blank=True, max_length=200, verbose_name=u"公告内容")
    start_time = models.DateTimeField(null=True, blank=True, verbose_name=u"播放开始时间")
    end_time = models.DateTimeField(null=True, blank=True, verbose_name=u"播放结束时间")
    start_day = models.DateField(null=True, blank=True, verbose_name=u"播放开始日期")
    end_day = models.DateField(null=True, blank=True, verbose_name=u"播放结束日期")
    create_user = models.CharField(max_length=20, null=True, blank=True, verbose_name=u"创建人员")
    update_user = models.CharField(max_length=20, null=True, blank=True, verbose_name=u"修改人员")
    qdesc = models.CharField(max_length=200, null=True, blank=True, verbose_name=u"队列描述")

    def resources(self):
        rmpqmr = ResourceManagementPlayingQueueMaterialRelation.objects.filter_active(material=self)
        if rmpqmr:
            l = []
            for r in rmpqmr:
                if r.resource:
                    l.append({"name": r.resource.name, "retention_time": r.retention_time, "id": r.id, "resource_id": r.resource.id})
            return l
        return []


class ResourceManagementPlayingQueueMaterialRelation(BaseModel):
    resource = models.ForeignKey(ResourceManagement, null=True, blank=True, verbose_name=u"资源")
    material = models.ForeignKey(PlayingQueueMaterial, null=True, blank=True, verbose_name=u"素材")
    retention_time = models.IntegerField(null=True, blank=True, default=0, verbose_name=u"保留时间")


class AuthorityCodePlayingQueueRelation(BaseModel):
    authority_code = models.ForeignKey(AuthorityCode, null=True, blank=True, verbose_name=u"外设")
    play_queue = models.ForeignKey(PlayingQueue, null=True, blank=True, verbose_name=u"对应的队列")






















































